<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="com.cndatacom.oa.voting.been.*" %>
<%@page import="com.cndatacom.oa.voting.VotingManagerUtils" %>
<%@page import="java.util.*" %>
<%@page import="java.sql.Timestamp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>北京研究院第九届（春季花卉）摄影比赛</title>
<link href="jx.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.STYLE1 {
	font-size: 12px;
	font-weight: bold;
}
-->
</style>

</head>


<% 
	String targetMatchNo = "1";//比赛编号
	long loginUserId = 2;//当前用户的ID，用于记录投票状况
	
	Timestamp tNowTime = new Timestamp(new java.util.Date().getTime());//获取当前时间，用户判断托票还没开始还是已经过期
	boolean validTime = true;//判断时间
	String validMessage = "";//返回时间错误的信息

	java.util.List list = new ArrayList();
	list = VotingManagerUtils.getAllVotePicInfo(targetMatchNo);//比赛作品列表
	VoteMatch vMatch = VotingManagerUtils.getVoteMatchInfo(targetMatchNo);//比赛信息
	
	int matchPicSum = 0;
	if(vMatch != null) {
		matchPicSum = vMatch.getPicSum();
		if(tNowTime.before(vMatch.getVoteStartTime())) {
			validTime = false;
			validMessage = "投票尚未开始！";
		}else if(tNowTime.after(vMatch.getVoteEndTime())) {
			validTime = false;
			validMessage = "投票已经结束！";
		}
	}
	
	int nVotedCount = 0;//已经投票次数
	if(VotingManagerUtils.getVoteUserByUserIdAndMatchNo((int)loginUserId, targetMatchNo) != null) {
		nVotedCount = VotingManagerUtils.getVoteUserByUserIdAndMatchNo((int)loginUserId, targetMatchNo).getVotedCount();
	}
	
	boolean canVote = VotingManagerUtils.checkUserCanVoteOrNot((int)loginUserId, targetMatchNo);
	String disable = "";
	if(!canVote) {
		disable = "disabled";
	}
	
%>



<body>
<div class="jx_bg">
<div class="jx_topBox2"><img src="images/banner.jpg" width="960" height="160" /></div>
<div class="jx_leftbox">
<div class="jx_toptitle1">共有<%=matchPicSum%>个候选作品</div>
<div class="jx_MainBox">
  <div class="jx_ContentBox"><table width="726" border="0" cellpadding="0" cellspacing="0">
  
  <% 
		for(int n=0; n<list.size(); n++) {
			VotePic votePic = (VotePic)list.get(n);
			String picTitle = votePic.getPicTitle();
			String picTitleShort = "";
			String picAuthodName = votePic.getAuthodName();
			String picNo = votePic.getPicNo();
			String picRemark = votePic.getPicRemark();
			
			if(picTitle != null) {
				if(picTitle.length()>14) {
					picTitleShort = picTitle.substring(0,14)+"..";
				}else {
					picTitleShort = picTitle;
				}
			}else {
				picTitle = "";
			}
			if(picAuthodName == null) {
				picAuthodName = "";
			}
			if(picNo == null) {
				picNo = "";
			}
			if(picRemark == null) {
				picRemark = "";
			}
	%>
	
	<%
		if(n%4 == 0) { 
	%>
		<tr>
	<% 
		}	
	%>
  
    <td width="183" valign="top"><table width="95%" border="0" cellspacing="0" cellpadding="0" class="jx_moduletb01">
      <tr>
	        <td height="140" align="center">
	        	<table  border="0" cellspacing="0" cellpadding="0">
	            	<tr>
	              		<td class="jx_moduletb02"><a href="detail.jsp?picid=<%=votePic.getId()%>" target="_blank"><img alt="<%=votePic.getPicRemark()%>" src="../<%=votePic.getMiniPicPath()%>"/></a></td>
	            	</tr>
	        	</table>
	        </td>
      </tr>
      
      <tr>
        	<td class="jx_moduletb03" title="<%=picTitle%>"><%=picNo%> <%=picTitleShort%> <%=picAuthodName%></td>
      </tr>
      
      <tr>
        <td class="jx_moduletb04">
        	<table width="150" border="0" cellspacing="0" cellpadding="0" class="jx_moduletd">
            	<tr>
              		<td width="31" class="jx_moduletd">投票</td>
              		<td width="119"><input type="checkbox" <%=disable%> name="checkbox" id="checkbox" value="<%=votePic.getId()%>"/></td>
            	</tr>
        	</table>
        </td>
      </tr>
    </table></td>
    
    <%
		if(n%4 == 3) { 
	%>
		</tr>
	<% 
		}	
	%>
	<%
		}
	%>  
    
</table>

    <div class="jx_button">
      <table width="98%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <%
        	if(canVote) {
        %>
          		<td width="21%"><a href="#" onclick="compilePic();return false;"><img src="images/index_10.gif" width="126" height="34" /></a></td>
        <%
        	}else {
        %>
        		<td width="21%"><img src="images/index_10g.gif" width="126" height="34" /></td>
        <%
        	}
        %>
          <td width="49%" align="left"><a href="result.jsp"><img src="images/index_14.gif" width="126" height="34" /></a></td>
          <td width="30%"><a href="#" onclick="return false;"><img src="images/index_12.gif" width="212" height="37" /></a></td>
        </tr>
      </table>
    </div>
  </div>
  </div>
</div>
<div class="jx_righttop"><img src="images/righttop.gif" /></div>
<div class="jx_rightbox">
  <p>1、投票有效时间为2011年5月4日0：00至2011年5月17日24：00。</p>
  <p>2、投票范围为本次展出的8幅“春季花卉”摄影作品；</p>
  <p>3、每名院内员工限投票1次，最多可选择5幅作品作为本次大赛“优秀作品”候选。</p>
  <p>4、投票作程中，不显示候选作品得票情况。</p>
</div>
<div class="jx_righttop"><img src="images/righttop1.gif" width="220" height="67" /></div>
<div class="jx_rightbox" style="height:510px; border-bottom:1px #D8D8D8 solid; ">
  <div class="jx_righttext03">
  	<a href="#">第八届大赛</a><br />
    <a href="#">第七届大赛</a><br />
    <a href="#">第六届大赛</a></div>
  </div>
<br>

<br>

</div>
<div class="jx_bg">
<div class="jx_BottomBox">中国电信北京研究院  版权所有</div>
</div>

		<form id="voteForm" name="voteForm" action="votedo.jsp" method="post">
			<input type="hidden" id="userid" name="userid"/>
			<input type="hidden" id="matchno" name="matchno"/>
			<input type="hidden" id="picids" name="picids"/>
		</form>

</body>
</html>

<script>
	function compilePic() {
		if(<%=validTime%>) {
			var checkedNum = 0;
			var checkIds = "";
			var temp = document.getElementsByName("checkbox");
			var len = temp.length;
			for(var i=0; i<len; i++){
	            if(temp[i].checked==true){
					checkedNum++;
					if(checkIds == "") {
						checkIds = temp[i].value;
					}else {
						checkIds = checkIds + ";" + temp[i].value;
					}
	            }       
	        }    
			//alert(checkedNum);
			if(checkedNum == 0) {
				alert("请先选择候选作品！");
				return false;
			}else if(checkedNum > 5) {
				alert("您已经选择了 "+checkedNum+" 幅作品，每人最多可以投 5 票，请确认！");
				return false;
			}else {
				if(!confirm("您已经选择了 "+checkedNum+" 幅作品，每人最多可以投 5 票，是否确定投票？")) {
					return false;
				}
			}
			//alert(checkIds);
			document.getElementById("userid").value = "<%=loginUserId%>";
			document.getElementById("matchno").value = "<%=targetMatchNo%>";
			document.getElementById("picids").value = checkIds;
			document.getElementById("voteForm").submit();
		}else {
			alert("<%=validMessage%>");
			return false;
		}
	}
	
	function resetCheckBox() {
		var temp = document.getElementsByName("checkbox");
		var len = temp.length;
		for(var i=0; i<len; i++){
		
            temp[i].checked = false;
                
        }    
	}
</script>
